<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="/luckydog/index"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li>账号管理</li>
        <li class="active">角色管理</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <!-- left column -->
        <div class="col-md-12">
        <!-- general form elements -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">添加账号</h3>
                </div>
                <div class="margin">
                    <form class="form-horizontal">
                        <input type="hidden" name="account_id" value="">
                        <div class="form-group">
                            <label class="col-md-2 control-label">姓名</label>
                            <div class="col-md-6">
                                <input class="form-control" type="text" name="truename" value="<?php echo is_object($account)?$account->truename:''?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <input type="hidden" name="user_id" value="<?php echo is_object($account)?$account->user_id:''?>">
                            <label class="col-md-2 control-label">用户名*(不能含字符'@')</label>
                        <div class="col-md-6">
                            <input class="form-control" type="text" name="username" value="<?php echo is_object($account)?$account->username:''?>" <?php echo isset($account->username)?'readonly':''?>>
                        </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">密码*</label>
                            <div class="col-md-6">
                                <input class="form-control" type="password" name="password" value="">
                            </div>
                        </div>
                        <div class="form-group">
                        <label class="col-md-2 control-label">再次输入密码*</label>
                            <div class="col-md-6">
                                <input class="form-control" type="password" name="password2" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <span class="btn btn-primary" id="tosave">保存</span> 
                            </div>
                        </div>
                    </form>  
                </div>
            </div>
        </div>
    </div>
</section>
<script>
    var url = "<?php echo is_object($account) && $account->user_id?URL::site('account/modify'):URL::site('account/save'); ?>";
    $('#tosave').click(function() {
        var truename = $("input[name='truename']").val()
        var username = $("input[name='username']").val()
        var password = $("input[name='password']").val()
        var password2 = $("input[name='password2']").val()
        $.post(url, {truename:truename,username:username,password:password,password2:password2}, function(data) {
            if(data.code) 
            {
                layer.msg(data.message);
                if(parent.$.find('.fancybox-overlay').length) {
                    parent.location="/account/list";
                }else{
                    location="/account/list";
                }
            } else {
                layer.msg(data.message);
            }
        }, "json");
        return false;
    });

</script>